//
//  ClassTableViewCell.m
//  UI_A项目
//
//  Created by dlios on 15-1-17.
//  Copyright (c) 2015年 songCheng. All rights reserved.
//

#import "ClassTableViewCell.h"

@implementation ClassTableViewCell

- (void)dealloc
{
    [_albumCoverUrl290ImageView release];
    [_albumCoverUrl290ImageView1 release];
    [_albumCoverUrl290ImageView2 release];
    [_lastUptrackAtLabel release];
    [_playsCountsLabel release];
    [_titleLabel release];
    [_labelButton release];
    [_viewButton release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    self.albumCoverUrl290ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 100, 120)];
    //    self.albumCoverUrl290ImageView.backgroundColor = [UIColor redColor];
    self.albumCoverUrl290ImageView.layer.masksToBounds = YES;
    self.albumCoverUrl290ImageView.layer.cornerRadius = 10;
    self.albumCoverUrl290ImageView.layer.borderWidth = 1;
    self.albumCoverUrl290ImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.contentView addSubview:self.albumCoverUrl290ImageView];
    [_albumCoverUrl290ImageView release];
    
    
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 25, 200, 30)];
    //    self.titleLabel.backgroundColor = [UIColor redColor];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.playsCountsLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x + 30, self.titleLabel.frame.origin.y + 40, 100, 30)];
    //    self.playsCountsLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.playsCountsLabel];
    [_playsCountsLabel release];
    
    self.albumCoverUrl290ImageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-iconfontbofang.png"]];
    self.albumCoverUrl290ImageView1.frame = CGRectMake(self.playsCountsLabel.frame.origin.x - 30, self.playsCountsLabel.frame.origin.y + 5, 20, 20);
    [self.contentView addSubview:self.albumCoverUrl290ImageView1];
    [_albumCoverUrl290ImageView1 release];
    
    
    self.lastUptrackAtLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.playsCountsLabel.frame.origin.x - 20, self.playsCountsLabel.frame.origin.y + 40, self.playsCountsLabel.frame.size.width + 120, self.playsCountsLabel.frame.size.height)];
    //    self.lastUptrackAtLabel.backgroundColor = [UIColor redColor];
    self.lastUptrackAtLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.lastUptrackAtLabel];
    [_lastUptrackAtLabel release];
    
    self.viewButton = [[UIView alloc] initWithFrame:CGRectMake(self.lastUptrackAtLabel.frame.origin.x + 140, self.lastUptrackAtLabel.frame.origin.y, 80, 30)];
    self.viewButton.layer.cornerRadius = 5;
    self.viewButton.layer.masksToBounds = YES;
    self.viewButton.layer.borderWidth = 1;
    
    self.viewButton.layer.borderColor = [UIColor blackColor].CGColor;
    //    self.viewButton.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.viewButton];
    [_viewButton release];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button setImage:[UIImage imageNamed:@"iconfont-jingpindingyuepad.png"] forState:UIControlStateNormal];
    self.button.frame = CGRectMake(5, 5, 20, 20);
    [self.viewButton addSubview:self.button];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.labelButton = [[UILabel alloc] initWithFrame:CGRectMake(self.button.frame.origin.x + 30, self.button.frame.origin.y, self.button.frame.size.width + 50, self.button.frame.size.height)];
    self.labelButton.font = [UIFont systemFontOfSize:18];
    self.labelButton.text = @"订阅";
    [self.viewButton addSubview:self.labelButton];
    [_labelButton release];
    
    
}
- (void)buttonAction:(UIButton *)button
{
    
}


- (void)setModel:(ClassModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.titleLabel.text = model.title;
    NSString *str = [NSString stringWithFormat:@"%@", model.playsCounts];
    self.playsCountsLabel.text = str;
    NSURL *url = [NSURL URLWithString:_model.albumCoverUrl290];
    [self.albumCoverUrl290ImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"d52a2834349b033b18d7c6dd16ce36d3d539bd5d.jpg"]];
    NSNumber *time = model.lastUptrackAt;
    NSDate *date = [[[NSDate alloc] initWithTimeIntervalSince1970:[time doubleValue]/1000.0] autorelease];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    NSString *str1 = [dateFormatter stringFromDate:date];
    NSString *str2 = [NSString stringWithFormat:@"Last update: %@", str1];
    self.lastUptrackAtLabel.text = str2;
    
    
    
    
    
}











- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
